#include "StdAfx.h"
#include "StrategyManager.h"

using namespace SmartTrade;


StrategyManager::StrategyManager(void)
{
	pStrategyMap_ = new map<string,Ptr_Strategy>();
	pContext_ = new StrategyContext();
	pEvtAdapter_ = new EventEngineAdapter(pStrategyMap_);
}


StrategyManager::~StrategyManager(void)
{
}

void StrategyManager::CreateStrategy(const string& strStratName){
	
	if(strStratName.length() == 0)
		return;

	map<string,Ptr_Strategy>::iterator i = pStrategyMap_->find(strStratName);
	if(i != pStrategyMap_->end())
		return;

	Ptr_Strategy pStrategy = BaseStrategy::Create(strStratName);
	if(pStrategy != NULL){
		pStrategy->SetContext(pContext_);
		StrategyMapValue value(strStratName,pStrategy);
		pStrategyMap_->insert(value);
	}
}

void StrategyManager::RunStrategy(){
	for(StrategyMapIterator i = pStrategyMap_->begin();i != pStrategyMap_->end(); ++i){
		i->second->StartStrategy();
	}
}

void StrategyManager::StopStrategy(){
	for(StrategyMapIterator i = pStrategyMap_->begin();i != pStrategyMap_->end(); ++i){
		i->second->StopStrategy();
	}
}
